package com.jdym.back.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.jdym.R;
import com.jdym.back.entity.Certify;
import com.jdym.back.entity.Check;
import com.jdym.back.entity.vo.CertifyRecord;
import com.jdym.back.service.CertifyService;
import com.jdym.back.service.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 资质认证审核表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-09-20
 */
@RestController
@CrossOrigin
@RequestMapping("/back/certify")
public class CertifyController {
    @Autowired
    CertifyService certifyService;
    @Autowired
    CheckService checkService;

//查询所有资质变更申请
    @RequestMapping(value = "/getAllCheck")
    public R getAllCheck(){

        List<CertifyRecord> certifyRecords= certifyService.getAllCheck();
        return R.ok().data("certify",certifyRecords);
    }
//    管理员同意更改
    @RequestMapping(value = "/agreeAlter/{cheId}/{certifyId}")
    public R agreeAlter(@PathVariable int cheId, @PathVariable int certifyId){
//        获取到新申请的记录
        System.out.println(cheId+"-----"+certifyId);
      Check check= checkService.selectCheck(cheId);
        System.out.println("check:"+check);
      Certify certify=new Certify();
      certify.setCertifyId(certifyId);
      certify.setLegalperson(check.getLegalperson());
      certify.setBusinessScope(check.getBusinessScope());
      certify.setBusinessType(check.getBusinessType());
      certify.setIndustry(check.getIndustry());
      certify.setContributors(check.getContributors());
      certify.setRegisterMaterial(check.getRegisterMaterial());
      certify.setStaffSize(check.getStaffSize());
      certify.setCheckId(cheId);
      certify.setCheckAdvice("");
//        将旧的记录更新
        certifyService.getBaseMapper().updateById(certify);
//        将审核状态更新
        checkService.updataCheckStatus(cheId);
        return R.ok();
    }
    @PutMapping(value = "/refuse/{certifyId}/{checkId}")
    public R refuse(@RequestParam String advice,@PathVariable int certifyId,@PathVariable int checkId){
        System.out.println("123445:"+advice+certifyId);
        Certify certify=new Certify();
        certify.setCheckAdvice(advice);
        certify.setCertifyId(certifyId);
        certifyService.getBaseMapper().updateById(certify);
      checkService.updataCheckStatus2(checkId);
        return R.ok();
    }
}

